﻿/*
 *  PassBag is multi-platform software that securely manage/store passwords
 *  Copyright (C) <2009>  <Hugo Rodrigues PEREIRA>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 *  You can find a copy of the GPLv3 at project <root directory>/gpl.txt
 *
 */

using System.Text;

namespace PassBag.Utils {
    /// <summary>
    /// UTF 8 converter class
    /// </summary>
    public sealed class UTF8Converter {
        /// <summary>
        /// Convert a Unicode Byte Array to a String.
        /// </summary>
        /// <param name="utf8ByteArray">Unicode Byte Array to convert to string</param>
        /// <returns>Converted string</returns>
        public static string UTF8ByteArrayAsString (byte[] utf8ByteArray) {
            UTF8Encoding encode = new UTF8Encoding ();
            string convertedString = encode.GetString (utf8ByteArray);
            return (convertedString);
        }

        /// <summary>
        /// Convert the string to UTF8 Byte array
        /// </summary>
        /// <param name="str"></param>
        /// <returns>Unicode Byte Array</returns>
        public static byte[] StringAsUTF8ByteArray (string str) {
            UTF8Encoding encode = new UTF8Encoding ();
            byte[] byteArray = encode.GetBytes (str);
            return byteArray;
        }
    }
}
